package regexObject;

//包装类的演示
public class IntegerDemo {
    public static void main(String[] args) {
        //1.用包装类来获取基本类型的取值范围;
        int max = Integer.MAX_VALUE;
        int min = Integer.MIN_VALUE;
        System.out.println("int最大值为:" + max);
        System.out.println("int最小值为:" + min);
        char maxValue = Character.MAX_VALUE;
        char minValue = Character.MIN_VALUE;
        System.out.println("char最大值为:" + maxValue);
        System.out.println("char最小值为:" + minValue);
        System.out.println("-------------------------------");
        //2)包装类可以将字符串转换为对应的基本类型----必须熟练掌握
        String s1 = "123";
        int i = Integer.parseInt(s1);
        System.out.println(i);
        String s2 = "123.123";
        double d = Double.parseDouble(s2);
        System.out.println(d);
        System.out.println("------------------------------");
//包装类自动装箱
        Integer i1 = new Integer(127);
        Integer i2 = Integer.valueOf(127);
       //自动装箱:编译器会自动把基本类型int 5,包装成包装类型Integer
        Integer i3 = 5;
        int i4 = i1;
        //自动拆箱:i1自动拆箱成int,并赋值给i4;
        System.out.println(i1==i2);//false
        System.out.println(i1.equals(i2));//true
        System.out.println("---------------");
        Integer i5=Integer.valueOf(5);
        Integer i6=Integer.valueOf(5);
        System.out.println(i5==i6);//true

        Integer i7=Integer.valueOf(128);
        Integer i8=Integer.valueOf(128);
        System.out.println(i7==i8);//false
        //在-128到127之间包装类已经加载好,超过这个范围时创建新包装类
    }
}
